package application;

import java.util.Arrays;

import junit.framework.TestCase;

import org.junit.*;

import static org.junit.Assert.*;

/* 
 * The JUnit class tests the output of DivePlanner.
 * The first half of the tests are single dives and the second half
 * 	test multiple dives.   
 */

public class JUnit extends TestCase {
	DivePlanner planner = new DivePlanner();
	private int maxDepth;
	private int minTime;
	private int minDepth;

	protected void setUp() {
		maxDepth = 130;
		minTime = 5;
		minDepth = 40;
	}

	public void testSingleLowest() {
		NAUITable nt = planner.addFirstDive(minDepth, minTime);
		String expected = "[DIVE: " + minTime + " min @" + minDepth + " ft.]";
		String result = Arrays.deepToString(planner.getPlanner().toArray());
		assertTrue(result.equals(expected));
	}

	public void testSingleMaxDepth() {
		NAUITable nt = planner.addFirstDive(maxDepth, 25);
		String expected = "[DIVE: " + 25 + " min @" + maxDepth
				+ " ft., DECOMPRESSION: 10 min @15 ft.]";
		String result = Arrays.deepToString(planner.getPlanner().toArray());
		assertTrue(result.equals(expected));
	}

	public void testSingleMaxDepthMDT() {
		NAUITable nt = planner.addFirstDive(maxDepth, 8);
		String expected = "[DIVE: " + 8 + " min @" + maxDepth + " ft.]";
		String result = Arrays.deepToString(planner.getPlanner().toArray());
		assertTrue(result.equals(expected));
	}

	public void testSingleMinDepthEdgeTime() {
		NAUITable nt = planner.addFirstDive(minDepth, 150);
		String expected = "[DIVE: " + 150 + " min @" + minDepth
				+ " ft., DECOMPRESSION: 5 min @15 ft.]";
		String result = Arrays.deepToString(planner.getPlanner().toArray());
		assertTrue(result.equals(expected));
	}

	public void testSingleMidDepthMaxTime() {
		NAUITable nt = planner.addFirstDive(80, 60);
		String expected = "[DIVE: " + 60 + " min @" + 80
				+ " ft., DECOMPRESSION: 17 min @15 ft.]";
		String result = Arrays.deepToString(planner.getPlanner().toArray());
		assertTrue(result.equals(expected));
	}

	public void testSingleMidDepthMDT() {
		NAUITable nt = planner.addFirstDive(80, 35);
		String expected = "[DIVE: " + 35 + " min @" + 80 + " ft.]";
		String result = Arrays.deepToString(planner.getPlanner().toArray());
		assertTrue(result.equals(expected));
	}

	public void testMultMinDepthMinTimeFAIL() {
		int repeatDives = 9;
		NAUITable nt = planner.addFirstDive(minDepth, minTime);
		for (int i = 0; i < repeatDives; i++) {
			planner.setUserSIT(10);
			planner.setUserDepthAndTime(minDepth, minTime);
			nt = planner.addRepetitiveDive(nt);
		}
		String result = Arrays.deepToString(planner.getPlanner().toArray());
		String expected = "[DIVE: 5 min @40 ft., SIT: 10 min @0 ft., DIVE: 5 min @40 ft., SIT: 10 min @0 ft., "
				+ "DIVE: 5 min @40 ft., SIT: 10 min @0 ft., DIVE: 5 min @40 ft., SIT: 10 min @0 ft., DIVE: 5 min"
				+ " @40 ft., SIT: 10 min @0 ft., DIVE: 5 min @40 ft., SIT: 10 min @0 ft., DIVE: 5 min @40 ft.,"
				+ " SIT: 10 min @0 ft., DIVE: 5 min @40 ft., SIT: 10 min @0 ft., DIVE: 5 min @40 ft., SIT: 10 min @0 ft., "
				+ "DIVE: 5 min @40 ft.]";
		assertTrue(result.equals(expected));
	}

	public void testMultMinDepthMinTimePASS() {
		int repeatDives = 9;
		NAUITable nt = planner.addFirstDive(minDepth, minTime);
		for (int i = 0; i < repeatDives; i++) {
			planner.setUserSIT(10);
			planner.setUserDepthAndTime(minDepth, minTime);
			nt = planner.addRepetitiveDive(nt);
		}
		String result = Arrays.deepToString(planner.getPlanner().toArray());
		String expected = "[DIVE: 5 min @40 ft., SIT: 10 min @0 ft., DIVE: 5 min @40 ft., SIT: 10 min @0 ft., "
				+ "DIVE: 5 min @40 ft., SIT: 10 min @0 ft., DIVE: 5 min @40 ft., SIT: 10 min @0 ft., DIVE: 5 min"
				+ " @40 ft., SIT: 10 min @0 ft., DIVE: 5 min @40 ft., SIT: 10 min @0 ft., DIVE: 5 min @40 ft.,"
				+ " SIT: 10 min @0 ft., DIVE: 5 min @40 ft., SIT: 10 min @0 ft., DIVE: 5 min @40 ft., SIT: 10 min @0 ft., "
				+ "DIVE: 5 min @40 ft.]";
		assertTrue(result.equals(expected));
	}

	public void testMultMaxDepthTime() {
		NAUITable nt = planner.addFirstDive(maxDepth, 25);
		// Dive 2
		planner.setUserSIT(2400);
		planner.setUserDepthAndTime(130, 5);
		nt = planner.addRepetitiveDive(nt);
		// Dive 3
		planner.setUserSIT(2400);
		planner.setUserDepthAndTime(130, 5);
		nt = planner.addRepetitiveDive(nt);

		String expected = "[DIVE: 25 min @130 ft., DECOMPRESSION: 10 min @15 ft., SIT: 2400 min @0 ft., DIVE: 5 min @130 ft., "
				+ "SIT: 2400 min @0 ft., DIVE: 5 min @130 ft.]";
		String result = Arrays.deepToString(planner.getPlanner().toArray());
		assertTrue(result.equals(expected));
	}

	public void testMultRandDepthTime() {
		NAUITable nt = planner.addFirstDive(60, 25);
		// Dive 2
		planner.setUserSIT(55);
		planner.setUserDepthAndTime(80, 15);
		nt = planner.addRepetitiveDive(nt);
		// Dive 3
		planner.setUserSIT(238);
		planner.setUserDepthAndTime(70, 20);
		nt = planner.addRepetitiveDive(nt);
		// Dive 4
		planner.setUserSIT(142);
		planner.setUserDepthAndTime(50, 40);
		nt = planner.addRepetitiveDive(nt);
		// Dive 5
		planner.setUserSIT(357);
		planner.setUserDepthAndTime(90, 5);
		nt = planner.addRepetitiveDive(nt);
		// Dive 6
		planner.setUserSIT(140);
		planner.setUserDepthAndTime(40, 30);
		nt = planner.addRepetitiveDive(nt);
		// Dive 7
		planner.setUserSIT(120);
		planner.setUserDepthAndTime(50, 10);
		nt = planner.addRepetitiveDive(nt);
		// Dive 8
		planner.setUserSIT(320);
		planner.setUserDepthAndTime(70, 15);
		nt = planner.addRepetitiveDive(nt);
		// Dive 9
		planner.setUserSIT(300);
		planner.setUserDepthAndTime(100, 10);
		nt = planner.addRepetitiveDive(nt);
		// Dive 10
		planner.setUserSIT(300);
		planner.setUserDepthAndTime(50, 15);
		nt = planner.addRepetitiveDive(nt);
		// Dive 11
		planner.setUserSIT(100);
		planner.setUserDepthAndTime(40, 20);
		nt = planner.addRepetitiveDive(nt);

		String expected = "[DIVE: 25 min @60 ft., SIT: 55 min @0 ft., DIVE: 15 min @80 ft., SIT: 238 min @0 ft., "
				+ "DIVE: 20 min @70 ft., SIT: 142 min @0 ft., DIVE: 40 min @50 ft., SIT: 357 min @0 ft., DIVE: 5 min"
				+ " @90 ft., SIT: 140 min @0 ft., DIVE: 30 min @40 ft., SIT: 120 min @0 ft., DIVE: 10 min @50 ft.,"
				+ " SIT: 320 min @0 ft., DIVE: 15 min @70 ft., SIT: 300 min @0 ft., DIVE: 10 min @100 ft., SIT: 300 min @0 ft.,"
				+ " DIVE: 15 min @50 ft., SIT: 100 min @0 ft., DIVE: 20 min @40 ft.]";
		String result = Arrays.deepToString(planner.getPlanner().toArray());
		assertTrue(result.equals(expected));
	}

}
